package com.haogu.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.haogu.entity.Business;
import com.haogu.entity.Contract;
import com.haogu.entity.VContract;
import com.haogu.mapper.BusinessMapper;
import com.haogu.mapper.ContractMapper;
import com.haogu.mapper.UserMapper;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

@Service
public class ContractService implements com.haogu.service.ContractService {
    @Resource
    private ContractMapper contractMapper;
    @Resource
    private BusinessMapper businessMapper;

    /**
     * 分页搜索contract
     * @param map
     * @return
     */
    @Override
    public List<VContract> listPage(Map map) {
        List<VContract> contracts = contractMapper.listPage(map);
        return contracts;
    }

    /**
     * 查询contract的数量
     * @return
     */
    public int selectCount(){
        QueryWrapper queryWrapper = new QueryWrapper();
        queryWrapper.select("id");
        Integer count = contractMapper.selectCount(queryWrapper);
        return count;
    }

    /**
     * 查询全部Business
     * @return
     */
    public List<Business> listBusiness(){
        QueryWrapper queryWrapper = new QueryWrapper();
        queryWrapper.comment("id");
        List list = businessMapper.selectList(queryWrapper);
        return list;
    }

    /**
     * 添加contract
     * @param contract
     * @return
     */
    public int addContract(Contract contract){
        int i = contractMapper.insert(contract);
        return i;
    }

    /**
     * 逻辑删除
     * @param id
     * @return
     */
    public int deleteContract(Integer id){
        int i = contractMapper.deleteById(id);
        return i;
    }

    /**
     * 根据id查contract
     * @param id
     * @return
     */
    public Contract selectContractById(Integer id){
        Contract contract = contractMapper.selectById(id);
        return contract;
    }
    public int updateContract(Contract contract){
        int i = contractMapper.updateById(contract);
        return i;
    }

    /**
     * 今日、周、月签约
     * @param map
     * @return
     */
    @Override
    public List<VContract> selectDay(Map map) {
        List<VContract> contracts = contractMapper.selectDay(map);
        return contracts;
    }

    /**
     *“我”创建、负责的
     * @param map
     * @return
     */
    @Override
    public List<VContract> selectByUser(Map map) {
        List<VContract> contractList = contractMapper.selectByUser(map);
        return contractList;
    }
}
